package com.shell.governor.modules.service.impl;

import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.base.utils.SystemUtil;
import com.shell.bee.entity.mvc.RetMsg;
import com.shell.bee.persistence.annotation.Pagination;
import com.shell.bee.persistence.model.PageLimit;
import com.shell.bee.persistence.service.impl.PersistentServiceImpl;
import com.shell.governor.modules.dao.PubApplicationDao;
import com.shell.governor.modules.po.PubApplication;
import com.shell.governor.modules.service.PubApplicationService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PubApplicationServiceImpl extends PersistentServiceImpl<PubApplication> implements PubApplicationService {
	@Autowired
	PubApplicationDao pubApplicationDao;

	@Pagination
	public List<PubApplication> getApplicationByPage(PageLimit limit, PubApplication pubApplication) {
		if (!StringUtil.emptyAndNull(pubApplication.getAppName())) {
			pubApplication.setAppName("%" + pubApplication.getAppName() + "%");
		}
		if (!StringUtil.emptyAndNull(pubApplication.getAppCode())) {
			pubApplication.setAppCode("%" + pubApplication.getAppCode() + "%");
		}
		List<PubApplication> list = this.pubApplicationDao.selectApplication(pubApplication);
		return list;
	}

	public RetMsg deletePubApplication(PubApplication pubApplication) {
		pubApplication.setAppState("D");
		int flag = this.pubApplicationDao.updateByPrimaryKey(pubApplication);
		if (flag == 1) {
			return new RetMsg("success", "��������������");
		}
		return new RetMsg("error", "��������������");
	}

	public RetMsg saveOrUpdatepubApplication(PubApplication pubApplication) {
		if (StringUtil.emptyAndNull(pubApplication.getAppId())) {
			pubApplication.setAppId(SystemUtil.getUUID());
		}
		int flag = saveOrUpdate(pubApplication);
		if (flag == 1) {
			return new RetMsg("success", "��������������");
		}
		return new RetMsg("error", "��������������");
	}

	public RetMsg updatePubApplicationStatus(PubApplication pubApplication) {
		int flag = this.pubApplicationDao.updateByPrimaryKeySelective(pubApplication);
		if (flag == 1) {
			return new RetMsg("success", "����������");
		}
		return new RetMsg("error", "����������");
	}

	public List<PubApplication> getApplication(PubApplication application) {
		List<PubApplication> list = this.pubApplicationDao.selectApplication(application);
		return list;
	}

	public List<PubApplication> getApplicationName(PubApplication application) {
		return this.pubApplicationDao.getAllAppName();
	}

	public PubApplication selectApplicationbyCode(String appCode) {
		PubApplication application = new PubApplication();
		application.setAppCode(appCode);
		application.setAppState("E");
		application = (PubApplication) selectOne(application);
		return application;
	}

	public List<PubApplication> selectCurUserApplication(String userId, String entId, String curAppId) {
		return this.pubApplicationDao.selectCurUserApplication(userId, entId, curAppId);
	}
}
